package com.click369.mianshiqingbao.controller;

import com.click369.mianshiqingbao.pojo.PaymentsBean;
import com.click369.mianshiqingbao.pojo.entity.PageResult;
import com.click369.mianshiqingbao.pojo.entity.Result;
import com.click369.mianshiqingbao.service.PaymentsService;
import com.click369.mianshiqingbao.util.StaticFinalFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 用户支付信息的控制器类
 */
@Controller
@RequestMapping("/payments")
public class PaymentsController {
    @Autowired
    private PaymentsService paymentsService;

    /**
     * 条件分页查询用户支付信息列表
     * @param paymentsbean 用户支付信息对象
     * @param page 页码
     * @param size 每页记录数
     * @return 分页查询信息的封装对象
     */
    @RequestMapping("/search.do")
    @ResponseBody
    public PageResult search(@RequestBody PaymentsBean paymentsbean, int page, int size){
        return paymentsService.findPage(paymentsbean,page, size);
    }

    /**
     * 新增用户支付信息
     * @param paymentsbean 用户支付信息对象
     * @return 成功或失败的提示信息封装类对象
     */
    @RequestMapping("/add.do")
    @ResponseBody
    public Result add(@RequestBody PaymentsBean paymentsbean){
        try {
            paymentsService.add(paymentsbean);
            return new Result(true, StaticFinalFile.SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,StaticFinalFile.FAILURE);
        }
    }

    /**
     * 根据id查询用户支付信息对象
     * @param id 用户支付ID
     * @return 用户支付信息对象
     */
    @RequestMapping("/findOne.do")
    @ResponseBody
    public PaymentsBean findOne(Long id){
        return paymentsService.findOne(id);
    }

    /**
     * 修改用户支付信息
     * @param paymentsbean 用户支付信息对象
     * @return 成功或失败的提示信息封装类对象
     */
    @RequestMapping("/update.do")
    @ResponseBody
    public Result update(@RequestBody PaymentsBean paymentsbean){
        try {
            paymentsService.update(paymentsbean);
            return new Result(true,StaticFinalFile.SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,StaticFinalFile.FAILURE);
        }
    }

    /**
     * 批量删除用户支付信息
     * @param ids 包含有被删除用户支付信息的ID数组
     * @return 成功或失败的提示信息封装类对象
     */
    @RequestMapping("/delete.do")
    @ResponseBody
    public Result delete(Long ids[]){
        try {
            paymentsService.delete(ids);
            return new Result(true,StaticFinalFile.SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,StaticFinalFile.FAILURE);
        }
    }
}
